package com.ss.project.xia17user.common.mbp;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 插入更新时自动生成指定数据
 * 插入时间 、 更新时间 、 插入人编号
 * @author xia17
 * @since 2020/9/8 21:46
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    /**
     * 新增时
     * @param metaObject /
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        // 起始版本 3.3.3(推荐)
        this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
        this.strictInsertFill(metaObject, "creator", ()->1L, Long.class);
    }

    /**
     * 更新时
     * @param metaObject /
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        // 起始版本 3.3.3(推荐)
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
    }
}
